library Wave12b initializer init requires LegacySystem, DeltaUtils

    private function Wave12c takes nothing returns nothing
        local integer i = 1
		local integer j = 1
        local integer ammocrates
		local boolean ammo_spawned = false
        set udg_CurrentWave = 12
        call GenericActions.execute()
        set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        set udg_Boss = CreateUnitAtLoc(Player(14),'U009',udg_myloc,0) //Atlas
        call SuspendHeroXP(udg_Boss, true)
        call RemoveLocation(udg_myloc)
		

        if udg_SquadXP>60000 and GetRandomInt(0,1)==1 then
            call RandomSpawn('e00Q',1,udg_Spawn) // Parasite Mound
        endif
        set i = 1
        loop
            exitwhen i>4
            call SpawnRectRandom(gg_rct_ADTSpawnWest,Player(14),'n002',GetRandomInt(1,3)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnEast,Player(13),'n002',GetRandomInt(1,2)*udg_Spawn)
            if i==1 then
                call RadioChat(udg_DeltaLeader, 6.0, "|cfff3ad00SSgt. Thompson|r : Our turrets will be more effective with some flares around the airbase." )
            endif
            call SpawnRectRandom(gg_rct_ADTSpawnEast,Player(13),'z002',GetRandomInt(1,2)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnSouth,Player(13),'n002',GetRandomInt(1,3)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnNorth,Player(14),'n002',GetRandomInt(1,4)*udg_Spawn)
            if GetRandomInt(0,4)==1 then
                call GankMarine(Player(14),'u005',2+udg_Spawn,1700,2500)
            endif
            call PolledWait(10.0*udg_Pace)
			
			if ammo_spawned == false and ( (i > 1 and GetRandomInt(0,1) == 1) or i == 4 ) then
				set ammo_spawned = true
				call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : We've found more ammunition at the side hangars. Bring them to the turrets!" )
				if udg_SquadXP>100000 then
					set ammocrates = 3
				else
					set ammocrates = 5
				endif
				set j = 1
				loop
					exitwhen j>ammocrates
					call CreateItem('shas',12000.0,9550.0)
					call TriggerSleepAction(0.)
					set j=j+1
				endloop
			endif
            set i=i+1
        endloop

        if udg_Players!=0 then
            if GetWidgetLife(udg_AITarget)>0.405 then
                call ExecuteRegisteredFunction("Wave13c")
                // call Wave13c.execute()
            else
                call ADTCleanup.execute()
                call DeltaExit.execute()
                call ExecuteRegisteredFunction("Wave13a")
                //call Wave13a.execute()
                call SetRevelationSpawnEnabled(true)
            endif
        endif
    endfunction

    private function Wave12b takes nothing returns nothing
        set udg_CurrentWave = 12
        call GenericActions.execute()
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : Here comes the next component." )
        call PolledWait(10.*udg_Pace)
        call SetDeltaSpawnEnabled(false)
        //call DisableTrigger(gg_trg_Delta_Wave_Spawn)
        set udg_Visibility = 63
        call IntermissionRestore()
        call M242Drop.execute()
        call PolledWait(20.*udg_Pace)
        call RandomSpawn('z002',1,udg_Players) //Slasher
        call FieldChat(udg_DeltaOperator[1], 5, "|cfff3ad00SSgt. Thompson|r : Fiesty fuckers." )
        call PolledWait(10.*udg_Pace)
        set udg_Visibility = 65
        call IntermissionRestore()
        call FieldChat(udg_DeltaOperator[GetRandomInt(1,5)], 5, "|cfff3ad00Delta Operator|r : We're watching your six, move along dude." )
        call PolledWait(40.*udg_Pace)
        call DeltaChapterSpawn()
        call DeltaChapterSpawn()
        call PolledWait(90.*udg_Pace)
        call SetDeltaSpawnEnabled(true)
        //call EnableTrigger(gg_trg_Delta_Wave_Spawn)
        if udg_Players!=0 then
            if udg_DeltaLeader==null then
                call DeltaExit.execute()
                call ExecuteRegisteredFunction("Wave13a")
                //call Wave13a.execute()
                call SetDeltaSpawnEnabled(false)
                //call DisableTrigger(gg_trg_Delta_Wave_Spawn)
                call SetRevelationSpawnEnabled(true)
            else
                call ExecuteRegisteredFunction("Wave13b")
                //call Wave13b.execute()
            endif
        endif
    endfunction

    private function init takes nothing returns nothing
        call RegisterFunction("Wave12b", function Wave12b)
        call RegisterFunction("Wave12c", function Wave12c)
        //call ExecuteRegisteredFunction("Wave12b")
    endfunction
endlibrary